package com.openlogic.logic.mapstruct;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.dozer.Mapper;
import org.noear.solon.annotation.Component;

import com.openlogic.common.core.mapstruct.EntityMapper;
import com.openlogic.datasource.api.dto.DataTableDto;
import com.openlogic.datasource.api.entity.DataTableEntity;
import com.openlogic.datasource.api.vo.DataTableVo;

/**
* @ClassName: DataTableMapperStruct
* @Description: 数据库表信息表 Mapper 实体映射
* @author weiyongpeng
* @date 2024年11月9日 上午10:50:36
 */
@Component
public class DataTableMapperStruct implements EntityMapper<DataTableDto, DataTableEntity, DataTableVo> {

	/**
     * dozer转换的核心mapper对象
     */
    public static final Mapper converter = new org.dozer.DozerBeanMapper();

	@Override
	public DataTableDto toDTO(DataTableEntity e) {
		return converter.map(e, DataTableDto.class);
	}

	@Override
	public List<DataTableDto> toDTO(List<DataTableEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataTableDto.class))
		        .collect(Collectors.toList());
	}

	@Override
	public DataTableVo toVO(DataTableEntity e) {
		return converter.map(e, DataTableVo.class);
	}

	@Override
	public List<DataTableVo> toVO(List<DataTableEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataTableVo.class))
		        .collect(Collectors.toList());
	}

	@Override
	public DataTableEntity toEntity(DataTableDto d) {
		return converter.map(d, DataTableEntity.class);
	}

	@Override
	public List<DataTableEntity> toEntity(List<DataTableDto> ds) {
		return Optional.ofNullable(ds)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataTableEntity.class))
		        .collect(Collectors.toList());
	}

}
